

var _m_url = window.parent._index_path;
/**
 * 加载用户的datagrid
 * @param colData
 * @param divName
 * @return
 */
function loadUserCol(){
	alert(2);
	$('#caq_USERLIST').datagrid({
		iconCls:'icon-save',
		url:_m_url+'framework/loadData?dsId=ds_bs_operators&config=&rows=1000',
		height:600 ,
		width:260, 
		striped: true,		
		collapsible:true,
		autoRowHeight: false,		
		sortOrder: 'desc',
		remoteSort: false,
		columns:[[
          {field:'kk',checkbox:true}, 
          {field:"O_ID",title:'员工编码',hidden:true},
          {field:"O_NAME",title:'员工名称',width:100,sortable:true},
          {field:"BUMEN",title:'所属部门',formatter:eval('window.parent.dz_bumenfmat'),width:100,sortable:true}
          ]],
		singleSelect:true,
		onClickRow:function(rowIndex,rowData){
			var oid = rowData.O_ID;
			//加载这个人所拥有的所有模块以及菜单
			$.ajax({
				type:'post',
				url:_m_url+'menu/listByUser',
				data:{'oid':oid},
				success:function(data){
				//将返回的信息给右下边的div
					showDiv(data);
				}
			})
		}
	});   
}
//单击用户时触发事件返回之后的界面操作
function showDiv(data){
	var haveGroup = data.haveGroup; //已有的组
    var noneGroup = data.noneGroup; //没有的组
    var haveModual = data.haveModual; //已有的模块
    var noneModual = data.noneModual; //没有的模块
    var dsList = data.dataStroeList; //第一个模块下的所有的功能
    $('#groupList').html("");  //没有
    $('#userGroup').html("");  //有
    $('#userModual').html(""); //没有
    $('#modualList').html(""); //有
    $('#leftModel').html("");//功能权限中左侧的div（模块）
    $('#dsByleft').html("");//功能权限中右侧的div
    $('#haveDs').html("");//功能权限中下面div
    $('#leftModelData').html("");//数据权限模块中存放模块的div
    $("#butnMoSel").empty();  //按钮权限模块中存放模块的下拉框
    $("#leftDSByMod").html(""); //按钮权限模块中存放功能的div
	$('#butByleft').html('');  //按钮权限模块中点击功能之后在右上侧的div
	$('#haveButn').html('');//按钮权限模块中存放允许和禁止按钮的div
    if(haveGroup != null){
    	var groupStr = "";
    	for(var i=0;i<haveGroup.length;i++){
    		groupStr="<div style='float: left; cursor: pointer; margin-left: 10px;  width:60px;' gId='"+haveGroup[i].GROUP_ID+"' align='center' flag='0' onclick=\"selColor(this)\">"+
				     "<p align='center'><img src=\"../model/images/right_yes.png\" /></p><p>"+haveGroup[i].GROUP_NAME+"</p></div>";
    		$('#userGroup').append(groupStr);
    	}
    }
    if(noneGroup!=null){
    	var nGroupStr ="";
    	for(var i=0;i<noneGroup.length;i++){
    		nGroupStr="<div style='float: left; cursor: pointer; margin-left: 10px;  width:60px;' gId='"+noneGroup[i].GROUP_ID+"' align='center' flag='0' onclick=\"selColor(this)\">"+
				     "<p align='center'><img src=\"../model/images/datebox_arrow.png\" /></p><p>"+noneGroup[i].GROUP_NAME+"</p></div>";
    		$('#groupList').append(nGroupStr);
    	}
    }
    if(haveModual != null){
    	var modualStr="";
    	var leftMoStr="";
    	var dataStr="";
    	var butnMoStr = "";
    	$("#butnMoSel").append("<option value='"+haveModual[0].MENU_ID+"'  selected='selected'>"+haveModual[0].MENU_NAME+"</option>");
    	for(var i=0;i<haveModual.length;i++){
    		modualStr ="<div style='float: left; cursor: pointer; margin-left: 10px; width:60px;' mId='"+haveModual[i].MENU_ID+"' flag='0' align='center' onclick=\"selColor(this)\">"+
				       "<p align='center'><img src=\"../model/images/right_yes.png\" /></p><p>"+haveModual[i].MENU_NAME+"</p></div>";
    		$('#modualList').append(modualStr);
    	
    		leftMoStr="<div style='cursor: pointer;' flag='0' onclick=\"selColorLeft(this)\" mId='"+haveModual[i].MENU_ID+"'>"+
				 	  "<p><img src=\"../model/images/jindu-no.png\" />"+haveModual[i].MENU_NAME+"</p></div>  ";
    		$('#leftModel').append(leftMoStr);
    	
    		dataStr="<div style='cursor: pointer;' flag='0' onclick=\"selMoForAllDs(this)\" mId='"+haveModual[i].MENU_ID+"'>"+
		 	  "<p><img src=\"../model/images/jindu-no.png\" />"+haveModual[i].MENU_NAME+"</p></div>  ";
    		$('#leftModelData').append(dataStr);
    		
    		if(i>0){
    			butnMoStr="<option value='"+haveModual[i].MENU_ID+"'>"+haveModual[i].MENU_NAME+"</option>";
    			$("#butnMoSel").append(butnMoStr);
    		}
    	}
    } 
    if(noneModual != null){
    	var nmodualStr="";
    	for(var i=0;i<noneModual.length;i++){
    		nmodualStr ="<div style='float: left; cursor: pointer; margin-left: 10px; width:60px;' mId='"+noneModual[i].menuId+"' flag='0' align='center' onclick=\"selColor(this)\">"+
				       "<p align='center'><img src=\"../model/images/jindu-no.png\" /></p><p>"+noneModual[i].menuName+"</p></div>";
    		$('#userModual').append(nmodualStr);
    	}
    }
    console.log(dsList[0]);
    var haveDS = dsList[0];
    if(haveDS != null){
    	var haveDsStr ="";
    	for(var i=0;i<dsList[0].length;i++){
			haveDsStr= "<div style=' cursor: pointer; width: 100%;' flag='0'  onclick=\"selDSLeft (this)\" dsId='"+haveDS[i].DS_ID+"'>"+
				      		"<p><img src=\"../model/images/jindu-row.png\" />"+haveDS[i].DS_NAME+"</p></div> "
			$('#leftDSByMod').append(haveDsStr);
		}
    }
    
}

//单个的选择样式(组和模块)
function selColor(obj){
	var flag = $(obj).attr('flag');
	if(flag == '0'){
		$(obj).css('background-color','#E0ECFF');
		$(obj).attr('flag','1');
	}else if(flag =='1'){
		$(obj).css('background-color','#ffffff');
		$(obj).attr('flag','0');
	}
}
//功能权限时调用的样式方法和调用加载相应的dataStore的方法
function selColorLeft(obj){
	var aobj = $('#leftModel div');
	for(var i = 0; i < aobj.length; i++){
		if($(aobj[i]).attr('flag') == '1' ){
			$(aobj[i]).css('background-color','#ffffff');
			$(aobj[i]).attr('flag','0');
		}
	}
	$(obj).css('background-color','#E0ECFF');
	$(obj).attr('flag','1');
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	var oid= "";
	if(selRows != null){
		oid = selRows.O_ID;  //获取选择的员工ID
	}
	//执行方法加载相应模块中的功能
	var mId = $(obj).attr('mId');//获取到点击模块的模块ID
	$.ajax({
		type:'post',
		url:_m_url+'menu/dsByModual',
		data:{'mId':mId,'oid':oid},
		success:function(data){
			if(data != null){
				if(oid == ""){
					var divStr = "";
					$('#dsByleft').html('');
					for(var i=0;i<data.length;i++){
						divStr= "<div style='float: left; cursor: pointer;  margin-left: 10px; width:60px;' flag='0' dsId='"+data[i].DS_ID+"' align='center' onclick='selColor(this)'>" +
						"<p align='center'><img src='../model/images/jindu-row.png' /></p><p>"+data[i].DS_NAME+"</p></div>"
						$('#dsByleft').append(divStr);
					}
				}else{
					var haveDS = data[0];
					var noneDS = data[2];
					var forbidDS = data[1];
					var divStr = "";
					var haveDsStr = "";
					var forbidStr = "";
					$('#dsByleft').html(''); //右上
					$('#haveDs').html('');//下
					for(var i=0;i<noneDS.length;i++){
						divStr= "<div style='float: left; cursor: pointer;  margin-left: 10px; width:60px;' flag='0' dsId='"+noneDS[i].DS_ID+"' align='center' onclick='selColor(this)'>" +
						"<p align='center'><img src='../model/images/jindu-row.png' /></p><p>"+noneDS[i].DS_NAME+"</p></div>"
						$('#dsByleft').append(divStr);
					}
					for(var i=0;i<haveDS.length;i++){
						haveDsStr= "<div style='float: left; cursor: pointer;  margin-left: 10px; width:60px;' flag='0' yorn='0' dsId='"+haveDS[i].DS_ID+"' align='center' onclick='selColor(this)'>" +
						"<p align='center'><img src='../model/images/right_yes.png' /></p><p>"+haveDS[i].DS_NAME+"</p></div>"
						$('#haveDs').append(haveDsStr);
					}
					for(var i=0;i<forbidDS.length;i++){
						haveDsStr= "<div style='float: left; cursor: pointer;  margin-left: 10px; width:60px;' flag='0' yorn='1' dsId='"+forbidDS[i].DS_ID+"' align='center' onclick='selColor(this)'>" +
						"<p align='center'><img src='../model/images/right_no.png' /></p><p>"+forbidDS[i].DS_NAME+"</p></div>"
						$('#haveDs').append(haveDsStr);
					}
				}
			}
		}
	})
}


//用户组权限中的添加按钮（将上面div中选中的组添加到下面div，并且在上面的div中移除）
function groupAdd(divName,adivName,flag){
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	if(selRows == null){
		$.messager.alert("提示","员工没有选择，请选择员工之后再添加或者删除！");
		return;
	}
	var aobj = $('#'+divName+' div');
	var pstr="<img src='../model/images/datebox_arrow.png' />";
	var ystr="<img src='../model/images/right_yes.png' />";
	var mstr="<img src='../model/images/jindu-no.png' />";
	for(var i = 0;i<aobj.length;i++){
		if($(aobj[i]).attr('flag') == '1' ){
			//从上面移除，获取这个div的html 添加到下面的div
			if(flag == 0){ //判断是添加还是移除
				$(aobj[i]).children('p').first().html(ystr);
			}else if(flag == 1){
				$(aobj[i]).children('p').first().html(pstr);
			}else if(flag == 2){
				$(aobj[i]).children('p').first().html(mstr);
			}
			$(aobj[i]).remove();
			$('#'+adivName).append($(aobj[i]));
		}
	}
}
//用户权限组的最后保存办法
function groupSave(){
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	if(selRows == null){
		$.messager.alert("提示","员工没有选择，请选择员工之后再添加！");
		return;
	}
	var oid= selRows.O_ID;  //获取选择的员工ID
	var objs = $('#userGroup div');
	var gIds = "";
	for(var i=0;i<objs.length;i++){
		gIds += $(objs[i]).attr('gid');
		if(i<objs.length-1){
			gIds+=';';
		}
	} 
	$.ajax({
		type:'post',
		url:_m_url+'menu/saveGroup',
		data:{'oid':oid,'gIds':gIds},
		success:function(data){
			if(data == "true"){
				$.messager.alert("提示","用户组权限设置成功！");
			}else{
				$.messager.alert("提示","用户组权限设置失败！");
			}
		}
	})
}
//模块最后的保存方法
function modualSave(){
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	if(selRows == null){
		$.messager.alert("提示","员工没有选择，请选择员工之后再添加！");
		return;
	}
	var oid= selRows.O_ID;  //获取选择的员工ID
	var objs = $('#modualList div');
	var mids = "";
	for(var i=0;i<objs.length;i++){
		mids += $(objs[i]).attr('mId');
		if(i<objs.length-1){
			mids+=';';
		}
	} 
	$.ajax({
		type:'post',
		url:_m_url+'menu/saveModual',
		data:{'oid':oid,'mids':mids},
		success:function(data){
			if(data == "true"){
				$.messager.alert("提示","模块权限设置成功！");
			}else{
				$.messager.alert("提示","模块权限设置失败！");
			}
		}
	})
}
//当模块选项卡被选中的时候调用的方法
function selClick(title){
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	var oid ="";
	if(selRows != null){
		oid = selRows.O_ID;
		//去重新加载这个用户所拥有的模块
		$.ajax({
			type:'post',
			url:_m_url+'menu/modualByUser',
			data:{'oid':oid},
			success:function(data){
				if(data != null){
					 var haveModual = data.haveModual; //已有的模块
					 var noneModual = data.noneModual; //没有的模块
					 $('#userModual').html(""); //没有
					 $('#modualList').html(""); //有
					 $("#butnMoSel").empty();  //按钮权限模块中存放模块的下拉框
					 $("#leftDSByMod").html(""); //按钮权限模块中存放功能的div
					 if(haveModual != null){
				    	var modualStr="";
				    	var leftMoStr="";  //赋给功能权限模块中的左侧--所有的模块
				    	var butnMoStr = "";
				    	$("#butnMoSel").append("<option value='"+haveModual[0].MENU_ID+"'  selected='selected'>"+haveModual[0].MENU_NAME+"</option>");
				    	for(var i=0;i<haveModual.length;i++){
				    		modualStr ="<div style='float: left; cursor: pointer; margin-left: 10px; width:60px;' mId='"+haveModual[i].MENU_ID+"' flag='0' align='center' onclick=\"selColor(this)\">"+
								       "<p align='center'><img src=\"../model/images/right_yes.png\" /></p><p>"+haveModual[i].MENU_NAME+"</p></div>";
				    		$('#modualList').append(modualStr);
				    		leftMoStr="<div style='cursor: pointer;' flag='0' onclick=\"selColorLeft(this)\" mId='"+haveModual[i].MENU_ID+"'>"+
								 	  "<p><img src=\"../model/images/jindu-no.png\" />"+haveModual[i].MENU_NAME+"</p></div>  ";
				    		$('#leftModel').append(leftMoStr);
				    		if(i>0){
				    			butnMoStr="<option value='"+haveModual[i].MENU_ID+"'>"+haveModual[i].MENU_NAME+"</option>";
				    			$("#butnMoSel").append(butnMoStr);
				    		}
				    	}
				    } 
				    if(noneModual != null){
				    	var nmodualStr="";
				    	for(var i=0;i<noneModual.length;i++){
				    		nmodualStr ="<div style='float: left; cursor: pointer; margin-left: 10px; width:60px;' mId='"+noneModual[i].menuId+"' flag='0' align='center' onclick=\"selColor(this)\">"+
								       "<p align='center'><img src=\"../model/images/jindu-no.png\" /></p><p>"+noneModual[i].menuName+"</p></div>";
				    		$('#userModual').append(nmodualStr);
				    	}
				    } 
				}
			}
		})
	}
}
//功能的添加按钮（包括允许和拒绝）
function gnAdd(){
	//1.先获取选择的模块Id
	var mId = "";
	var aobj = $('#leftModel div');
	for(var i = 0;i<aobj.length;i++){
		if($(aobj[i]).attr('flag') == '1' ){
			mId = $(aobj[i]).attr('mId');
		}
	}
	//2.获取是允许还是拒绝
	var yorn = "";
	yorn = $("input[name='yorn']:checked").val();
	//3.获取dsByleft这个div中选中的功能
	var dobj = $('#dsByleft div');
	var pstr="<img src='../model/images/right_no.png' />";
	var ystr="<img src='../model/images/right_yes.png' />";
	for(var i = 0;i<dobj.length;i++){
		if($(dobj[i]).attr('flag') == '1' ){
			//4.修改这些选中的div中的属性
			$(dobj[i]).attr('mId',mId);
			if(yorn == "1"){
				$(dobj[i]).attr('yorn','1');
				$(dobj[i]).children('p').first().html(pstr);
			}else{
				$(dobj[i]).attr('yorn','0');
				$(dobj[i]).children('p').first().html(ystr);
			}
			$(dobj[i]).remove();
			//5.将这些div填充到haveDs这个div中
			$('#haveDs').append($(dobj[i]));
		}
	}
}
//功能的移除按钮
function gnDel(){
	var dobj = $('#haveDs div');
	for(var i = 0;i<dobj.length;i++){
		if($(dobj[i]).attr('flag') == '1' ){
			var yorn = $(dobj[i]).attr("yorn");
			var pstr="<img src='../model/images/jindu-row.png' />";
			if(yorn == "1"){
				$(dobj[i]).children('p').first().html(pstr);
			}
			$(dobj[i]).remove();
			$('#dsByleft').append($(dobj[i]));
		}
	}
}
//反权限按钮
function contraryAuthority(divName){
	var dobj = $('#'+divName+' div');
	for(var i = 0;i<dobj.length;i++){
		if($(dobj[i]).attr('flag') == '1' ){
			if($(dobj[i]).attr('yorn')=='0'){//允许 变 拒绝
				$(dobj[i]).attr('yorn','1');
				$(dobj[i]).children('p').first().html("<img src='../model/images/right_no.png' />");
			}else if($(dobj[i]).attr('yorn')=='1'){ //拒绝 变 允许
				$(dobj[i]).attr('yorn','0');
				$(dobj[i]).children('p').first().html("<img src='../model/images/right_yes.png' />");
			}
		}
	}
}
//保存功能
function gnSave(){
	var mId = "";
	var aobj = $('#leftModel div');
	for(var i = 0;i<aobj.length;i++){
		if($(aobj[i]).attr('flag') == '1' ){
			mId = $(aobj[i]).attr('mId');
		}
	}
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	var oid ="";
	if(selRows != null){
		oid = selRows.O_ID;
	}else{
		$.messager.alert("提示","用户未选择，请选择用户！");
		return;
	}
	var dsList = new Array();
	var dobj = $('#haveDs div');
	for(var i = 0;i<dobj.length;i++){
		var haList = {};
		haList.gnId = $(dobj[i]).attr("dsid");
		haList.yorn = $(dobj[i]).attr("yorn");
		dsList.push(haList);
	}
	$.ajax({
		type:'post',
		url:_m_url+"menu/dsSavegn?mId="+mId+"&oid="+oid,
		contentType: "application/json;charset=utf-8",
		dataType: "json",
		data:JSON.stringify(dsList),
		success:function(data){
			if(data == true){
				$.messager.alert('提示','保存成功！');
			}else if(data == false){
				$.messager.alert('提示','保存失败！');
			}
		}
	})
}
//数据权限的模块点击的事件
function selMoForAllDs(obj){
	var aobj = $('#leftModelData div');
	for(var i = 0; i < aobj.length; i++){
		if($(aobj[i]).attr('flag') == '1' ){
			$(aobj[i]).css('background-color','#ffffff');
			$(aobj[i]).attr('flag','0');
		}
	}
	$(obj).css('background-color','#E0ECFF');
	$(obj).attr('flag','1');
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	//执行方法加载相应模块中的功能
	var mId = $(obj).attr('mId');//获取到点击模块的模块ID
	$.ajax({
		type:'post',
		url:_m_url+'menu/dsByModual',
		data:{'mId':mId,'oid':''},
		success:function(data){
			var divStr = "";
			$('#dsByleftData').html('');
			for(var i=0;i<data.length;i++){
				divStr= "<div style='float: left; cursor: pointer;  margin-left: 10px; width:60px;' flag='0' dsId='"+data[i].DS_ID+"' align='center' onclick='selDsForSql(this)'>" +
				"<p align='center'><img src='../model/images/jindu-row.png' /></p><p>"+data[i].DS_NAME+"</p></div>"
				$('#dsByleftData').append(divStr);
			} 
		}
	})
}
//数据权限的功能点击事件
function selDsForSql(obj){
	var aobj = $('#dsByleftData div');
	for(var i = 0; i < aobj.length; i++){
		if($(aobj[i]).attr('flag') == '1' ){
			$(aobj[i]).css('background-color','#ffffff');
			$(aobj[i]).attr('flag','0');
		}
	}
	$(obj).css('background-color','#E0ECFF');
	$(obj).attr('flag','1');
	var dsId = $(obj).attr('dsId');
	$.ajax({
		type:'post',
		url:_m_url+'menu/sqlForModual',
		data:{'dsId':dsId}, 
		success:function(data){
			$('#sqlTextArea').val(data.msg);
			$('#sqlTextDS').val(data.info);
		}
	})
}
//数据权限中的测试Sql按钮执行的方法（目前这个方法停用）
function testSQL(){
	var sql = $('#sqlTextArea').val();
	$.ajax({
		type:'post',
		url:_m_url+'menu/execSql',
		data:{'sql':sql},
		success:function(data){
			if(data == true){
				$('#sqlResult').append('执行成功！');
			}else{
				$('#sqlResult').append('执行失败！');
			}
		}
	})
}
//数据权限中sql的保存按钮执行的方法
function saveWhereSql(){
	var whereStr = $('#sqlTextArea').val();
	var dsId = "";
	var aobj = $('#dsByleftData div');
	for(var i = 0; i < aobj.length; i++){
		if($(aobj[i]).attr('flag') == '1' ){
			dsId = $(aobj[i]).attr('dsid');
		}
	}
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	var oid ="";
	if(selRows != null){
		oid = selRows.O_ID;
	}else{
		$.messager.alert("提示信息","用户未选择，请选择用户！");
		return;
	}
	$.ajax({
		type:'post',
		url:_m_url+'menu/saveWhereSql',
		data:{'dsId':dsId,'whereStr':whereStr,'oid':oid},
		success:function(data){
			if(data){
				$.messager.alert('提示信息','保存成功！');
			}else{
				$.messager.alert('提示信息','保存失败！');
			}
		}
	})
}
//按钮权限模块中模块下拉框变化时执行的方法
function optChangeDs(moName){
	 $("#leftDSByMod").html("");
	 $('#butByleft').html('');
	 $('#haveButn').html('');//下
	 var mId = $("#butnMoSel").val();
	 var selRows = $('#caq_USERLIST').datagrid('getSelected');
	 var oid= "";
	 if(selRows != null){
	 	oid = selRows.O_ID;  //获取选择的员工ID
	 }
	 $.ajax({
		type:'post',
		url:_m_url+'menu/dsByModual',
		data:{'mId':mId,'oid':oid},
		success:function(data){
			var haveDS=new Array();
			var divStr = "";
			if(data != null){
				if(oid == ""){
					haveDS= data;
				}else{
					haveDS = data[0];
				}
				for(var i=0;i<haveDS.length;i++){
					haveDsStr= "<div style=' cursor: pointer; width: 100%;' flag='0'  onclick=\"selDSLeft (this)\" dsId='"+haveDS[i].DS_ID+"'>"+
						      		"<p><img src=\"../model/images/jindu-row.png\" />"+haveDS[i].DS_NAME+"</p></div> "
					$('#leftDSByMod').append(haveDsStr);
				}
			}
		}
	})
}
//按钮权限模块中点击左侧菜单的样式，以及右侧加载
function selDSLeft(obj){
	var aobj = $('#leftDSByMod div');
	for(var i = 0; i < aobj.length; i++){
		if($(aobj[i]).attr('flag') == '1' ){
			$(aobj[i]).css('background-color','#ffffff');
			$(aobj[i]).attr('flag','0');
		}
	}
	$(obj).css('background-color','#E0ECFF');
	$(obj).attr('flag','1');
	var dsId = $(obj).attr('dsId');
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	var oid= "";
	if(selRows != null){
		oid = selRows.O_ID;  //获取选择的员工ID
	}
	$('#butByleft').html('');
	$('#haveButn').html('');//下
	$.ajax({
		type:'post',
		url:_m_url+'menu/butnByDS',
		data:{'dsId':dsId,'oid':oid},
		success:function(data){
			if(data != null){
				if(oid == ""){
					var divStr = "";
					for(var i=0;i<data.length;i++){
						divStr= "<div style='float: left; cursor: pointer;  margin-left: 10px; width:60px;' flag='0' name='"+data[i].BUTN_NAME+"' butnId='"+data[i].DS_ID+"' code='"+data[i].BUT_CODE+"' align='center' onclick='selColor(this)'>" +
						"<p align='center'><img src='../model/images/jindu-row.png' /></p><p>"+data[i].BUTN_NAME+"</p></div>"
						$('#butByleft').append(divStr);
					}
				}else{
					var haveButn = data[0];
					var forbidButn = data[1];
					var noneButn = data[2];
					var divStr = "";
					var haveDsStr = "";
					var forbidStr = "";
					for(var i=0;i<noneButn.length;i++){
						divStr= "<div style='float: left; cursor: pointer;  margin-left: 10px; width:60px;' flag='0' name='"+noneButn[i].BUTN_NAME+"' butnId='"+noneButn[i].DS_ID+"' code='"+noneButn[i].BUT_CODE+"' align='center' onclick='selColor(this)'>" +
						"<p align='center'><img src='../model/images/jindu-row.png' /></p><p>"+noneButn[i].BUTN_NAME+"</p></div>"
						$('#butByleft').append(divStr);
					}
					for(var i=0;i<haveButn.length;i++){
						haveDsStr= "<div style='float: left; cursor: pointer;  margin-left: 10px; width:60px;' flag='0' yorj='0' name='"+haveButn[i].BUTN_NAME+"' butnId='"+haveButn[i].DS_ID+"' code='"+haveButn[i].BUT_CODE+"' align='center' onclick='selColor(this)'>" +
						"<p align='center'><img src='../model/images/right_yes.png' /></p><p>"+haveButn[i].BUTN_NAME+"</p></div>"
						$('#haveButn').append(haveDsStr);
					}
					for(var i=0;i<forbidButn.length;i++){
						haveDsStr= "<div style='float: left; cursor: pointer;  margin-left: 10px; width:60px;' flag='0' yorj='1' name='"+forbidButn[i].BUTN_NAME+"' butnId='"+forbidButn[i].DS_ID+"' code='"+forbidButn[i].BUT_CODE+"' align='center' onclick='selColor(this)'>" +
						"<p align='center'><img src='../model/images/right_no.png' /></p><p>"+forbidButn[i].BUTN_NAME+"</p></div>"
						$('#haveButn').append(haveDsStr);
					}
				}
			}
		}
	})
}
//按钮的添加按钮（包括允许和拒绝）
function butnAdd(){
	//1.先获取选择的功能Id
	var dsId = "";
	var butnCode = "";
	var aobj = $('#leftDSByMod div');
	for(var i = 0;i<aobj.length;i++){
		if($(aobj[i]).attr('flag') == '1' ){
			dsId = $(aobj[i]).attr('dsId');
		}
	}
	//2.获取是允许还是拒绝
	var yorn = "";
	yorn = $("input[name='yorj']:checked").val();
	//3.获取butnByleft这个div中选中的功能
	var dobj = $('#butByleft div');
	var pstr="<img src='../model/images/datebox_arrow.png' />";
	for(var i = 0;i<dobj.length;i++){
		if($(dobj[i]).attr('flag') == '1' ){
			//4.修改这些选中的div中的属性
			$(dobj[i]).attr('dsId',dsId);
			if(yorn == "1"){
				$(dobj[i]).attr('yorj','1');
				$(dobj[i]).children('p').first().html(pstr);
			}else{
				$(dobj[i]).attr('yorj','0');
			}
			$(dobj[i]).remove();
			//5.将这些div填充到haveDs这个div中
			$('#haveButn').append($(dobj[i]));
		}
	}
}
//按钮的移除按钮
function butnDel(){
	var dobj = $('#haveButn div');
	for(var i = 0;i<dobj.length;i++){
		if($(dobj[i]).attr('flag') == '1' ){
			var yorn = $(dobj[i]).attr("yorj");
			var pstr="<img src='../model/images/jindu-row.png' />";
			if(yorn == "1"){
				$(dobj[i]).children('p').first().html(pstr);
			}
			$(dobj[i]).remove();
			$('#butByleft').append($(dobj[i]));
		}
	}
}
//按钮的保存
function butnSave(){
	var dsId = '';
	var aobj = $('#leftDSByMod div');
	for(var i = 0;i<aobj.length;i++){
		if($(aobj[i]).attr('flag') == '1' ){
			dsId = $(aobj[i]).attr('dsId');
		}
	}
	var selRows = $('#caq_USERLIST').datagrid('getSelected');
	var oid ="";
	if(selRows != null){
		oid = selRows.O_ID;
	}else{
		$.messager.alert("提示","用户未选择，请选择用户！");
		return;
	}
	var butnList = new Array();
	var dobj = $('#haveButn div');
	for(var i = 0;i<dobj.length;i++){
		var haList = {};
		haList.butnId = $(dobj[i]).attr("butnId");
		haList.butnName = $(dobj[i]).attr("name");
		haList.butnCode = $(dobj[i]).attr('code');
		haList.yorn = $(dobj[i]).attr("yorj");
		butnList.push(haList);
	}
	$.ajax({
		type:'post',
		url:_m_url+'menu/dsSaveButn?dsId='+dsId+"&oid="+oid,
		contentType: "application/json;charset=utf-8",
		dataType: "json",
		data:JSON.stringify(butnList),
		success:function(data){
			if(data == true){
				$.messager.alert('提示','保存成功！');
			}else if(data == false){
				$.messager.alert('提示','保存失败！');
			}
		}
	})
}